package cmd

import (
	"gitee.com/YunFeiGuoJi/golearning/pkg/config"
	"github.com/spf13/cobra"
)

// configCmd represents the config command
var configCmd = &cobra.Command{
	Use:   "config",
	Short: "Create cluster configuration file",
	RunE: func(cmd *cobra.Command, args []string) error {
		err := config.GenerateClusterObj(opt.Kubernetes, opt.Name, opt.Kubeconfig, opt.ClusterCfgPath, opt.FromCluster)
		if err != nil {
			return err
		}
		return err
	},
}

func init() {
	createCmd.AddCommand(configCmd)
	configCmd.Flags().StringVarP(&opt.Name, "name", "", "sample", "Specify a name of cluster object")
	configCmd.Flags().StringVarP(&opt.ClusterCfgPath, "filename", "f", "", "Specify a configuration file path")
	configCmd.Flags().StringVarP(&opt.Kubernetes, "with-kubernetes", "", "", "Specify a supported version of kubernetes")
	configCmd.Flags().BoolVarP(&opt.FromCluster, "from-cluster", "", false, "Create a configuration based on existing cluster")
	configCmd.Flags().StringVarP(&opt.Kubeconfig, "kubeonfig", "", "", "Specify a kubeconfig file")
}
